package com.otis.payroll;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class payrollTxtManupulation {
    public static void insert_Apppend(java.util.List list, String path, boolean wra) throws SQLException {
        BufferedWriter out = null;
    //    CallableStatement cs = null;
        try {
            File file = new File(path);
            if (!file.exists()) {
                file.createNewFile();
            }
            out = new BufferedWriter(new FileWriter(file, wra));
            for (Object s : list) {
                out.write((String) s);
                out.newLine();
            }
         //   cs.addBatch();
      //      int[] i= cs.executeBatch();
     //           System.out.println(i);
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void deleteFile(String path) {
        boolean bool = false;
        try {
            File file = new File(path);
            bool = file.exists();
            System.out.println("File exists: " + bool);
            if (bool == true) {
                file.delete();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void deleteData(String path) throws UserDefinedException{
        BufferedWriter out = null;
        File file = new File(path);
        try {
            if (!file.exists()) {
                System.out.println("file not found");
                 throw new UserDefinedException(path);
            }
            out = new BufferedWriter(new FileWriter(file));
            out.write("");
        } catch (IOException ex) {
            ex.printStackTrace();
        }   
    }
    }